<?php
    if($_FILES['news_img']['name']!='')
    {
        $handle = new Upload($_FILES['news_img']);
        if ($handle->uploaded)
        {
            $handle->image_resize = true;
            $handle->image_ratio_fill = true;
            $handle->image_background_color = '#ffffff';
            $handle->image_x = 1080;
            $handle->image_y = 483;
            
            $handle->Process(APPPATH.'/images/home_slide');
            if ($handle->processed)
            {
                $sql = 'INSERT INTO home_slide(hs_path) VALUES("'.$handle->file_dst_name.'")';
                $result = $db->Execute($sql);
                if($result)
                {
                    $msg = 'บันทึกข้อมูลเรียบร้อยแล้ว';
                }
                else
                {
                    if(img_exists(APPPATH.'/images/home_slide',$handle->file_dst_name)){
                        @unlink(APPPATH.'/images/home_slide/'.$handle->file_dst_name);
                    }
                    $msg = 'ไม่สามารถอัพโหลดรูปได้';
                }
            }
            else
            {
                $msg = 'ไม่สามารถอัพโหลดรูปได้';
            }

        }
        else
        {
            $msg = 'ไม่สามารถอัพโหลดรูปได้';
        }
    }else{
        $msg = 'กรุณาเลือกรูปที่จะอัพโหลด';
    }
?>

<?php
    include('header.php');
    include('submenu.php');
?>
<div class="grid_18" id="contents">
    <div id="query_result">
    <?php
        echo $msg , ' <img src="images/ajax-loader.gif" />';
        redirect('?m=main&s=slide',3);
    ?>
    </div>
</div><!-- end .grid_18 -->
<div class="clear">&nbsp;</div>
<?php
    include('footer.php');
?>